// context/SerialContext.ts
import React, { createContext } from 'react';

export interface SerialState {
  isSerialOpen: boolean;
  isSerialSearch: boolean;
  isSerialUpgrade: boolean;
}

export const initialSerialState: SerialState = {
  isSerialOpen: false,
  isSerialSearch: false,
  isSerialUpgrade: false,
};

export interface GlobalModel {
  global_serial_id: string;
}

export const initialGlobalModel: GlobalModel = {
  global_serial_id: '',
};

export interface ServoModel {
  inside_error: number;
  servo_id: number;
  servoMode?: boolean; // 是否为舵机模式
}

export const initialServoModel: ServoModel = {
  inside_error: 0,
  servo_id: 0,
};

export interface SerialContextType {
  serialState: SerialState;
  setSerialState: React.Dispatch<React.SetStateAction<SerialState>>;
  globalModel: GlobalModel;
  setGlobalModel: React.Dispatch<React.SetStateAction<GlobalModel>>;
  servoModel: ServoModel;
  setServoModel: React.Dispatch<React.SetStateAction<ServoModel>>;
}

export const SerialContext = createContext<SerialContextType | null>(null);
